<template>
  <div>
    <Navbar :appTitle="appTitle" @ClickRight="ClickRight" />
    <div
      class="form-content wrap-apply"
      :style="{
        top: GLOBAL.currentEnvironment ? '0' : '',
        height: GLOBAL.currentEnvironment ? '100vh' : 'calc(100vh - 100px)',
        paddingBottom: GLOBAL.currentEnvironment ? '120px' : '',
      }"
    >
      <van-cell-group>
        <p class="label required FormTit"><span></span>入库单编号</p>
        <div class="haveUnitBox">
          <van-field
            v-model="buildForm.entryCode"
            :maxLength="21"
            placeholder="请输入、不输入则自动生成"
          />
        </div>
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group>
        <p class="label required FormTit"><span></span>入库类型</p>
        <van-field-select-picker
          :supportClear="true"
          label=""
          placeholder="请选择"
          v-model="buildForm.inWarehouseType"
          :columns="warehousingTypes"
          :option="{ label: 'itemText', value: 'itemValue' }"
          @confirm="inWarehouseTypeConfirm"
        />
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group
        v-if="buildForm.inWarehouseType && buildForm.inWarehouseType == '1'"
      >
        <p class="label FormTit"><span></span>生产工单</p>
        <van-field
          readonly
          :is-link="!buildForm.produceOrderName"
          placeholder="请选择"
          v-model="buildForm.produceOrderName"
          @click="addProduceOrder"
        >
          <div
            slot="right-icon"
            v-show="!!buildForm.produceOrderName && !parentId"
            @click.stop="deleteProduceOrder"
          >
            <img src="~@/assets/img/filedClear.png" alt="" class="filedClear" />
          </div>
        </van-field>
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group
        v-if="buildForm.inWarehouseType && buildForm.inWarehouseType == '2'"
      >
        <p class="label FormTit"><span></span>销售订单</p>
        <van-field
          readonly
          :is-link="!buildForm.saleOrderName"
          placeholder="请选择"
          v-model="buildForm.saleOrderName"
          @click="addSaleOrder"
        >
          <div
            slot="right-icon"
            v-show="!!buildForm.saleOrderName && !parentId"
            @click.stop="deleteSaleOrder"
          >
            <img src="~@/assets/img/filedClear.png" alt="" class="filedClear" />
          </div>
        </van-field>
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group>
        <p class="label FormTit"><span></span>送入人</p>
        <van-field
          :is-link="!buildForm.sendPersionName"
          :value="buildForm.sendPersionName"
          placeholder="请选择"
          @click="isEdit ? '' : (selectShow = true)"
          readonly
          :disabled="isEdit"
        >
          <div
            slot="right-icon"
            v-show="!!buildForm.sendPersionName && !parentId"
            @click.stop="confirmDdtjr"
          >
            <img
              src="~@/assets/img/filedClear.png"
              alt=""
              style="width: 16px"
            />
          </div>
        </van-field>
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group>
        <p class="label required FormTit"><span></span>入库时间</p>
        <van-field
          is-link
          readonly
          name="picker"
          v-model="buildForm.inWarehouseTime"
          @click="timePickShow = true"
          placeholder="请选择"
        >
        </van-field>
        <div class="bottomLine"></div>
      </van-cell-group>

      <van-cell-group style="margin:10px 0;">
        <p class="label otherText">自定义信息</p>
        <div class="bottomLine"></div>
        <div
          v-if="formTypeExtendedFields && formTypeExtendedFields.length != 0"
        >
          <div v-for="(p, index) in formTypeExtendedFields" :key="index">
            <p class="label FormTit" :class="{ required: p.fieldMust == 2 }">
              <span></span>{{ p.fieldName }}
            </p>
            <van-field
              :placeholder="p.placeholder"
              v-model="buildForm.extDataJson[p.fieldKey]"
              :readonly="p.fieldMust == 1"
              :type="p.fieldType == 3 ? 'number' : 'input'"
              :maxlength="p.fieldLength || '-'"
              :formatter="(value) => clearNoNumTwo(value, p.fieldType)"
            />
            <div class="bottomLine"></div>
          </div>
        </div>
        <van-empty v-else description="自定义信息为空" />
      </van-cell-group>

      <van-cell-group
        v-for="(p, i) in entryDetails"
        :key="i + '_' + p.serialId"
        style="margin-top: 5px;"
      >
        <p
          class="label otherText"
          style="display: flex; justify-content: space-between"
        >
          入库物品明细（{{ i + 1 }}）<span
            style="font-weight: 400; color: #ff4d4f"
            @click="deleteGoods(i)"
            v-if="entryDetails.length > 1"
            >删除</span
          >
        </p>
        <div class="bottomLine"></div>
        <p class="label required FormTit"><span></span>物品</p>
        <van-field
          readonly
          :is-link="!p.serialLongName"
          placeholder="请选择"
          v-model="p.serialLongName"
          @click="projectVisible(i)"
        >
        </van-field>
        <div class="bottomLine"></div>
        <p class="label FormTit"><span></span>规格</p>
        <van-field
          readonly
          placeholder="根据选中的物品回显"
          v-model="p.serialSpecifications"
        />
        <div class="bottomLine"></div>
        <p class="label FormTit"><span></span>单位</p>
        <van-field
          placeholder="根据选中的物品回显"
          v-model="p.serialUnit"
          readonly
        />
        <div class="bottomLine"></div>
        <p class="label required FormTit"><span></span>数量</p>
        <van-field
          placeholder="请输入"
          type="number"
          maxLength="16"
          v-model="p.inWarehouseNum"
          :formatter="(e) => needInNumChange(e)"
        />

        <div class="bottomLine"></div>
        <div
          v-if="goodsTypeExtendedFields && goodsTypeExtendedFields.length != 0"
        >
          <div v-for="(p2, index2) in goodsTypeExtendedFields" :key="index2">
            <p class="label FormTit" :class="{ required: p2.fieldMust == 2 }">
              <span></span>{{ p2.fieldName }}
            </p>
            <van-field
              :placeholder="p2.placeholder"
              v-model="p[p2.fieldKey]"
              :readonly="p2.fieldMust == 1"
              :type="p2.fieldType == 3 ? 'number' : 'input'"
              :maxlength="p2.fieldLength || '-'"
              :formatter="(value) => clearNoNumTwo(value, p2.fieldType)"
            />
            <div class="bottomLine"></div>
          </div>
        </div>
      </van-cell-group>
      <div class="addGoodScontain">
        <div class="addgoods" @click="addInventoryGoods">
          <van-icon name="plus" size="16px" color="#1890ff" style="top: 2px" />
          <a>添加物品</a>
        </div>
        <div class="addgoods">
          <scanInputGoods ref="scanGoodsInput" @changeScan="changeScan" />
        </div>
      </div>

      <div class="search-bottoms">
        <span class="btnconfirm" @click="btnConfirm">提交</span>
      </div>
    </div>
    <!--选择送入人 -->
    <ContactPickers
      :key="'sendPersion'"
      :visible="selectShow"
      ref="mychild"
      :max="1"
      @closePicker="selectShow = false"
      @confirm="confirmSendPersion"
    />
    <!--选择入库日期 -->
    <van-popup v-model="timePickShow" position="bottom">
      <van-datetime-picker
        @confirm="confirmPick"
        v-model="happenTime"
        @cancel="cancelPick"
        type="datetime"
        title="入库时间"
        :formatter="formatter"
      />
    </van-popup>
    <!--选择物品 -->
    <goods-pickers
      v-if="showGoodsPicker"
      :listUrl="listUrl"
      :columns="goodsColumns"
      :selectedGoods="entryDetails"
      @getCheckedGoods="getCheckedGoods"
    ></goods-pickers>
    <!--生产工单 -->
    <produceOrder-pickers
      v-if="showProduceOrderPickers"
      :listUrl="produceOrderlistUrl"
      :columns="produceOrderColumns"
      :selectedProduceOrder="selectedProduceOrder"
      @getCheckedProduceOrder="getCheckedProduceOrder"
    ></produceOrder-pickers>
    <!--销售订单 -->
    <saleOrder-pickers
      v-if="showSaleOrderPickers"
      :listUrl="saleOrderPickerslistUrl"
      :columns="saleOrderColumns"
      :selectedProduceOrder="selectedSaleOrder"
      @getCheckedProduceOrder="getCheckedSaleOrder"
    ></saleOrder-pickers>
  </div>
</template>
<script>
import { clearNoNum } from "@/utils/util";
import { getAction } from "@/api/manage";
import moment from "moment";
import Navbar from "@/components/navBar/navBar_right";
import {
  inventoryOrderTypeList,
  formTypeExtendedFieldList,
  inventoryOrderAdd,
  inventoryOrDerEdit,
  inventoryOrderDetail,
  inventoryOrderDetailList,
} from "@/api/mobile";
import VanFieldSelectPicker from "@/components/ActionSheet/VanFieldSelectPicker";
import ContactPickers from "@/components/choiceuse/ContactPickers";
import GoodsPickers from "@/components/choiceuse/GoodsPickers";
import produceOrderPickers from "@/components/choiceuse/produceOrderPickers";
import saleOrderPickers from "@/components/choiceuse/saleOrderPickers";
import store from "@/store";
import scanInputGoods from "@/components/scanCode/scanInputGoods";
import { APILX } from "@/api/requestLx";
import { workOrderList } from "@/api/productionApply";
export default {
  name: "inventoryOrderForm",
  components: {
    Navbar,
    VanFieldSelectPicker,
    ContactPickers,
    GoodsPickers,
    scanInputGoods,
    produceOrderPickers,
    saleOrderPickers,
  },
  data() {
    return {
      activeIndex: 0,
      examKey: 1,
      //辅助单位
      buildForm: {
        entryCode: "",
        inWarehouseType: "1",
        produceOrderId: "",
        produceOrderName: "",
        saleOrderId: "",
        saleOrderName: "",
        sendPersion: "",
        sendPersionName: "",
        inWarehouseTime: "",
        extDataJson: {},
      },
      entryDetails: [{}],
      happenTime: new Date(),
      appTitle: "新建入库单",
      isEdit: false,
      parentId: "",
      showExam: true,
      warehousingTypes: [],
      selectShow: false,
      timePickShow: false,
      formTypeExtendedFields: [],
      goodsTypeExtendedFields: [],
      showGoodsPicker: false,
      listUrl: "/basicserial/basicSerialInfo/list",
      goodsColumns: {
        titleKey: "serialName", //标题
        content: [
          //内容
          {
            name: "物品编号",
            key: ["serialNumber"],
          },
          {
            name: "规格",
            key: ["serialSpecifications"],
          },
          {
            name: "单位",
            key: ["unitName"],
          },
        ],
        // labelKey: ["updateTime", "serialSpecifications"], //标签
        operationText: "",
      },

      showProduceOrderPickers: false,
      produceOrderlistUrl: "/produceorder/produceOrderInfo/list",
      produceOrderColumns: {
        titleKey: "orderCode", //标题
        content: [
          //内容
          {
            name: "生产物品",
            key: ["serialName"],
          },
          {
            name: "计划时间",
            key: ["timePeriod"],
          },
          {
            name: "计划生产数量",
            key: ["planProduceNum"],
          },
        ],
        labelKey: ["orderStatusText"], //标签
        operationText: "",
      },
      selectedProduceOrder: [],

      showSaleOrderPickers: false,
      saleOrderPickerslistUrl: "/sale/saleOrderInfo/list",
      saleOrderColumns: {
        titleKey: "orderCode", //标题
        content: [
          //内容
          {
            name: "客户",
            key: ["customName"],
          },
          {
            name: "物品种类",
            key: ["serialInfoCount"],
          },
          {
            name: "工单数",
            key: ["produceInfoCount"],
          },
        ],
        operationText: "",
      },
      selectedSaleOrder: [],
    };
  },
  beforeRouteLeave(to, from, next) {
    if (this.showPeopleSlect) {
      this.$refs.examine.closePicker();
      next(false);
    } else if (
      this.showGoodsPicker ||
      this.showProduceOrderPickers ||
      this.showSaleOrderPickers
    ) {
      this.showGoodsPicker = false;
      this.showProduceOrderPickers = false;
      this.showSaleOrderPickers = false;
      this.appTitle = this.isEdit ? "编辑入库单" : "新建入库单";
      next(false);
    } else {
      next();
    }
  },
 async created() {

       // 扫工单码进入
       if (this.$route.query.formPage == "scanCode" && this.$route.query.code.EntityType == 'workOrder') {
        let itemRes = await workOrderList({id:this.$route.query.code.id})
       this.getCheckedProduceOrder(itemRes.result.records)
       } 

        // 扫物品码进入
       if (this.$route.query.formPage == "scanCode" && this.$route.query.code.EntityType == 'goods') {
          this.changeScan(this.$route.query,'scan')
       } 


    store.commit("SET_CURRENT_PREFIX", "/jksaas-produce/produce");

    if(this.$route.query.id) {
      this.isEdit = true
      this.parentId = this.$route.query.id;
    }else {
      this.isEdit = false
      this.parentId = ''
    }
    this.buildForm.inWarehouseTime = moment(this.happenTime).format(
      "YYYY-MM-DD HH:mm"
    );
    let currentLoginUser = JSON.parse(
      localStorage.getItem("pro__Login_Userinfo")
    ).value;
    console.log("currentLoginUser", currentLoginUser);

    this.buildForm.sendPersion = currentLoginUser.id;
    this.buildForm.sendPersionName = currentLoginUser.realname;
    if (this.parentId) {
      this.appTitle = "编辑入库单";
      // 入库单表单详情
      inventoryOrderDetail({ id: this.parentId }).then((res) => {
        if (res.code == 200) {
          let resObj = res.result;
          for (let k in this.buildForm) {
            this.buildForm[k] = resObj[k];
          }
        }
      });
      // 入库单关联物品详情
      inventoryOrderDetailList({ entryId: this.parentId, inOutType: 0 }).then(
        (res) => {
          if (res.code == 200 && res.result) {
            this.entryDetails = res.result.records.map((son) => {
              return {
                serialId: son.serialId,
                serialLongName: son.serialName + "|" + son.serialNumber,
                serialName: son.serialName || "-",
                serialNumber: son.serialNumber || "-",
                serialSpecifications: son.serialSpecifications || "-",
                serialUnit: son.unitName || "-",
                inWarehouseNum: son.inWarehouseNum || null,
                ...son.extDataJson,
              };
            });
          }
        }
      );
    }
    this.initData();
  },
  methods: {
    // 入库类型 清空 生产订单 销售订单相关字段
    inWarehouseTypeConfirm(data1, index, data2) {
      if(data1) {
        let that = this
        if(that.buildForm.inWarehouseType != data2) {
          this.buildForm.produceOrderId = ''
          this.buildForm.produceOrderName = ''

          this.buildForm.saleOrderId = ''
          this.buildForm.saleOrderName = ''

          this.entryDetails = [{}]
          this.$forceUpdate()
        }
      }
    },
    // 自定义字段格式化
    clearNoNumTwo(value, type) {
      if(type != 3) {
        return value
      }else {
        return value.replace(/[^\d]/g, '')
      }
    },
    // 提交
    btnConfirm() {
      if (!this.buildForm.inWarehouseType) {
        this.$toast(`请选择入库类型`);
        return;
      }

      if (!this.buildForm.inWarehouseTime) {
        this.$toast(`请选择入库时间`);
        return;
      }

      let isValidated = true;
      try {
        this.formTypeExtendedFields.forEach((element) => {
          if (element.fieldMust == 2) {
            if (
              !this.buildForm.extDataJson[element.fieldKey] ||
              this.buildForm.extDataJson[element.fieldKey] == ""
            ) {
              isValidated = false;

              throw new Error(`自定义信息（${element.fieldName}）不可为空`);
            }
          }
        });

        // 自定义字段 必填项表单验证

        if (!isValidated) {
          return;
        }

        // 入库物品明细 为空 选项名称、数量 表单验证
        if (this.entryDetails && this.entryDetails.length > 0) {
          this.entryDetails.forEach((element, index) => {
            if (element.serialId) {
              if (!element.inWarehouseNum || element.inWarehouseNum == "") {
                isValidated = false;
                throw new Error(`入库物品明细（${index + 1}）数量不可为空`);

                this.$toast(`入库物品明细（${index + 1}）数量不可为空`);
                return;
              } else {
                this.goodsTypeExtendedFields.forEach((ele) => {
                  if (ele.fieldMust == 2) {
                    if (!element[ele.fieldKey] || element[ele.fieldKey] == "") {
                      throw new Error(
                        `入库物品明细（${index + 1}）\n 自定义信息（${
                          ele.fieldName
                        }）不可为空`
                      );

                      this.$toast(
                        `入库物品明细（${index + 1}）\n 自定义信息（${
                          ele.fieldName
                        }）不可为空`
                      );
                      isValidated = false;
                      return;
                    }
                  }
                });
              }
            } else {
              isValidated = false;
              throw new Error(`请选择入库物品`);

              this.$toast(`请选择入库物品`);
              return;
            }
          });
        } else {
          isValidated = false;
          throw new Error(`请选择入库物品`);

          this.$toast(`请选择入库物品`);
          return;
        }

        if (!isValidated) {
          return;
        }
      } catch (error) {
        this.$toast(error.message);
        return false;
      }
      this.handleSubmit();
    },
    handleSubmit() {
      let params = {
        ...this.buildForm,
        entryDetails: this.entryDetails.map((ele) => {
          let { serialId, inWarehouseNum } = ele;
          let extDataJson = {};

          this.goodsTypeExtendedFields.forEach((item) => {
            extDataJson[item.fieldKey] = ele[item.fieldKey];
          });

          return {
            serialId: serialId,
            inWarehouseNum: inWarehouseNum,
            extDataJson: extDataJson,
          };
        }),
      };

      let commitApi = "";
      let successMeg = "";
      if (this.parentId) {
        params.id = this.parentId;
        commitApi = inventoryOrDerEdit;
        successMeg = "入库单编辑成功！";
      } else {
        commitApi = inventoryOrderAdd;
        successMeg = "入库单创建成功！";
      }

      commitApi(params).then((res) => {
        if (res.success) {
          this.$toast(successMeg);
          this.$router.go(-1);
        } else {
          this.$toast(res.message);
        }
      });
    },
    // 初始化页面数据
    initData() {
      // 获取入库类型
      inventoryOrderTypeList().then((res) => {
        if (res.code == 200 && res.result) {
          this.warehousingTypes = res.result;
        }
      });
      // 获取出入库单 自定义表单字段;
      formTypeExtendedFieldList({ formType: 5 }).then((res) => {
        if (res.code == 200 && res.result) {
          this.formTypeExtendedFields = res.result;
        }
      });
      // 获取入库单关联物品 自定义表单字段;
      formTypeExtendedFieldList({ formType: 6 }).then((res) => {
        if (res.code == 200 && res.result) {
          this.goodsTypeExtendedFields = res.result;
        }
      });
    },
    // 送入人删除
    confirmDdtjr() {
      this.buildForm.sendPersion = "";
      this.buildForm.sendPersionName = "";
    },
    // 送入人选中
    confirmSendPersion(id, items) {
      if (!id) {
        this.confirmDdtjr();
      } else {
        this.buildForm.sendPersion = id;
        this.buildForm.sendPersionName = items[0].realname;
      }
      this.selectShow = false;
    },
    // 确定选择时间
    confirmPick(date) {
      this.buildForm.inWarehouseTime = moment(date).format("YYYY-MM-DD HH:mm");
      this.timePickShow = false;
    },
    // 取消选择时间
    cancelPick() {
      this.timePickShow = false;
    },
    formatter(type, val) {
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      if (type === "hour") {
        return val + "时";
      }
      if (type === "minute") {
        return val + "分";
      }
      return val;
    },
    // 入库物品明细-》添加
    addInventoryGoods() {
      this.appTitle = "入库物品选择";
      this.showGoodsPicker = true;
    },
    // 入库物品明细-》删除
    deleteGoods(i) {
      this.entryDetails.splice(i, 1);
    },
    // 入库物品明细-》物品弹出层
    projectVisible(i) {
      this.appTitle = "入库物品选择";
      this.showGoodsPicker = true;
    },
    // 确认选中物品
    async getCheckedGoods(list) {
      this.showGoodsPicker = false;
      this.appTitle = this.isEdit ? "编辑入库单" : "新建入库单";

      this.entryDetails = list.map((son) => {

        let recIndex = this.entryDetails.findIndex((ele) =>ele.serialId == son.id)

        let extData = {};
        if (son.extDataJson) {
          extData = son.extDataJson;
        }
        
        if(recIndex != -1) {
          let recObj = this.entryDetails[recIndex]
          return recObj
        }else {
          return {
            serialId: son.id,
            serialLongName: son.serialNumber + "|" + son.serialName,
            serialName: son.serialName || "-",
            serialNumber: son.serialNumber || "-",
            serialSpecifications: son.serialSpecifications || "-",
            serialUnit: son.unitName || "-",
            inWarehouseNum: null,
            ...extData,
          };
        }
      });
    },
    // 扫码获取物品
    changeScan(v, opratorType) {
      if (opratorType == "scan") {
        if (v.code.EntityType !== "goods") {
          this.$toast("请扫正确二维码");
          return;
        }

        getAction("/basicserial/basicSerialInfo/queryById", {
          id: v.code.id,
        }).then((res) => {
          if (res.code == 200 && res.result) {
            let ids = this.entryDetails.map((item) => item.serialId);
            if (ids.includes(res.result.id)) {
              this.$toast("该物品已存在");
              return;
            } else {
              let {
                id,
                serialName,
                serialNumber,
                serialSpecifications,
                unitName,
              } = res.result;
              let newGoods = {
                serialId: id,
                serialLongName: serialName + "|" + serialNumber,
                serialName: serialName || "-",
                serialNumber: serialNumber || "-",
                serialSpecifications: serialSpecifications || "-",
                serialUnit: unitName || "-",
                inWarehouseNum: null,
              };
              if(this.entryDetails && this.entryDetails.length == 1) {
                if(!this.entryDetails[0].serialId) {
                  this.entryDetails = []
                  this.entryDetails.push(newGoods); 
                }else {
                  this.entryDetails.push(newGoods);
                }
              }else {
                this.entryDetails.push(newGoods);
              }
              
              this.$forceUpdate();
            }
            // for (const goods of this.entryDetails) {
            //   if (goods.serialId == res.result.sid) {
            //     this.$toast("该物品已存在");
            //     break;
            //   } else {
            //     let {
            //       sid,
            //       serialName,
            //       serialNumber,
            //       serialSpecifications,
            //       serialUnit,
            //     } = res.result;
            //     let newGoods = {
            //       serialId: sid,
            //       serialLongName: serialName + "|" + serialNumber,
            //       serialName: serialName || "-",
            //       serialNumber: serialNumber || "-",
            //       serialSpecifications: serialSpecifications || "-",
            //       serialUnit: serialUnit || "-",
            //       inWarehouseNum: null,
            //     };
            //     this.entryDetails.push(newGoods);
            //     this.$forceUpdate();
            //   }
            // }
          }
        });
      }
    },

    // 生产工单-》添加
    addProduceOrder() {
      this.appTitle = "生产工单选择";
      this.showProduceOrderPickers = true;
    },
    // 生产工单-》删除
    deleteProduceOrder() {
      this.buildForm.produceOrderId = "";
      this.buildForm.produceOrderName = "";
      this.selectedProduceOrder = [];
    },
    // 确认选中生产工单
    async getCheckedProduceOrder(list) {
      if (!list[0].id) {
        return;
      } else {
        this.buildForm.produceOrderId = list[0].id;
        this.buildForm.produceOrderName = list[0].orderCode;
        this.selectedProduceOrder = list;
      }
      this.showProduceOrderPickers = false;
      this.appTitle = this.$route.meta.title;

      APILX.produceOrderInfoQueryById({ id: list[0].id }).then((res) => {
        if (res.code == 200) {
          this.entryDetails = [
            ...res.result.records.map((item) => {
              let {
                serialId,
                serialName,
                serialNumber,
                serialSpecifications,
                unitName,
                planProduceNum,
                maxQualifiedNum,
              } = item;
              return {
                serialId: serialId,
                serialLongName: serialNumber + "|" + serialName,
                serialName: serialName || "-",
                serialNumber: serialNumber || "-",
                serialSpecifications: serialSpecifications || "-",
                serialUnit: unitName || "-",
                inWarehouseNum: maxQualifiedNum,
              };
            }),
          ];
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 销售订单-》添加
    addSaleOrder() {
      this.appTitle = "销售订单选择";
      this.showSaleOrderPickers = true;
    },
    // 销售订单-》删除
    deleteSaleOrder() {
      this.buildForm.saleOrderId = "";
      this.buildForm.saleOrderName = "";
      this.selectedSaleOrder = [];
    },
    // 确认选中销售订单
    async getCheckedSaleOrder(list) {
      if (!list[0].id) {
        return;
      } else {
        this.buildForm.saleOrderId = list[0].id;
        this.buildForm.saleOrderName = list[0].orderCode;
        this.selectedSaleOrder = list;
      }
      this.showSaleOrderPickers = false;
      this.appTitle = this.$route.meta.title;

      APILX.saleOrderDetail(list[0].id).then((res) => {
        if (res.code == 200) {
          if (res.result.records && res.result.records.length != 0) {
            this.entryDetails = res.result.records.map((ele) => {
              return {
                serialId: ele.bsiId,
                serialLongName: ele.serialCode + "|" + ele.serialName,
                serialName: ele.serialName || "-",
                serialNumber: ele.serialNumber || "-",
                serialSpecifications: ele.serialSpecifications || "-",
                serialUnit: ele.unitName || "-",
                inWarehouseNum: null,
              };
            });
          }
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 入库单 物品明细 数量处理
    needInNumChange(e) {
      let value = clearNoNum(e);
      return value;
    },

    ClickRight() {
      this.showGoodsPicker = false;
      this.$router.push({
        path: "/application",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/theme.scss";
@import "@/views/workManagement/materialRequisition/materialForm.scss";
.form-content {
  width: 100%;
  height: calc(100vh - 203px);
  background: #f5f5f5;
  overflow: scroll;
  padding: 20px 0;
  .formgroup {
    background: #ffffff;
    // padding: 0 0.16rem;
    margin-top: 0.1rem;
    margin-bottom: 0.2rem;
    padding-top: 0.1rem;

    .title {
      width: 0.58rem;
      height: 0.14rem;
      font-size: 0.15rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #191f25;
      line-height: 0.05rem;
      margin-left: 0.16rem;
    }
  }
  .search-bottoms {
    width: 100%;
    height: 100px;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0rem 11px;
    box-sizing: border-box;
    font-size: 32px;
    font-weight: 500;
    z-index: 9;
    .btnconfirm {
      flex: 1;
      background: #1890ff;
      box-sizing: border-box;
      height: 78px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 6px;
      color: #ffffff;
    }
  }
}
.bottomLine {
  height: 1px;
  background-color: #f2f2f2;
  margin: 0 2px;
}
.otherText {
  font-size: 32px;
  font-weight: bold;
  color: #191f25;
}
.haveUnitBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding-right: 32px;
  /deep/ .van-cell {
    padding-right: 0;
    width: 600px;
  }
  /deep/ .van-field__control {
    max-width: 700px;
  }
}
/deep/ .van-nav-bar {
  z-index: 99;
}
/deep/.van-sidebar-item--select::before {
  color: #1890ff;
  background-color: #1890ff;
}
/deep/.van-tree-select__item--active {
  color: #1890ff;
}
.addGoodScontain {
  display: flex;
  flex-wrap: nowrap;
  .addgoods {
    flex: 1;
    background: #fff;
    font-size: 32px;
    text-align: center;
    height: 78px;
    line-height: 78px;
    color: #1890ff;
  }
}
.required span::after {
  left: -20px;
  top: 3px;
}
.filedClear {
  width: 28px;
  height: 28px;
}
</style>
